package com.myapp.core;

public class AritmeticTree {
	private TreeNode root;
	private TreeNode currentNode;

	public AritmeticTree(String aritmeticExpression) {
		// separate the expression onto its components (operators/operands) and
		// use add to build the tree
	}

	private boolean add(int value, boolean isOp) {
		if (root == null) {
			root = new TreeNode(value, isOp);
			currentNode = root;
		} else {
			if (isOp && currentNode.isOperation()) {
				return false;
			}

			if (currentNode.isOperation()) {// current node is operation, the
											// new must be operand
				TreeNode newNode = new TreeNode(value, false);

				if (!currentNode.hasLeft()) {
					currentNode.setLeftChild(newNode);
				} else if (!currentNode.hasRight()) {
					currentNode.setRightChild(newNode);
				}

				currentNode = newNode;
				return true;
			} else {// current node is operand, the new must be operation
				TreeNode newNode = new TreeNode(value, true);
				currentNode.switchContext(newNode);

				if (!currentNode.hasLeft()) {
					currentNode.setLeftChild(newNode);
				} else if (!currentNode.hasRight()) {
					currentNode.setRightChild(newNode);
				}

				currentNode = newNode;
				return true;
			}
		}

		return false;
	}

	public boolean evaluateTree() {
		//run dfs and use self-evaluate on every node
		return false;
	}
}
